"""
DateTime时间模块
"""
from datetime import datetime, timedelta

now = datetime.now()
print(now)

# 获取时间分量
print(now.date()) # 年月日
print(now.year)
print(now.month)
print(now.day)
print(now.hour)
print(now.minute)
print(now.second)

print('=' * 30)
# 字符串和时间进行转换
# 1. 将DateTime类型转换成str类型
str_now = now.strftime('%Y年%m月%d日 %H:%M:%S')
print(str_now)
print(type(str_now))
# 2. 将str类型转换成DateTime类型
birthday = '2004-5-6'
date_birthday = datetime.strptime(birthday, '%Y-%m-%d')
print(date_birthday)
print(type(date_birthday))